package com.gulimall.ware.controller;


import com.gulimall.common.core.domain.Result;
import com.gulimall.ware.service.IWareSkuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品库存 前端控制器
 * </p>
 *
 * @author 坤哥
 * @since 2025-08-27
 */
@Slf4j
@RestController
@RequestMapping("/ware/wareSku")
public class WareSkuController {
    @Resource
    private IWareSkuService wareSkuService;

    /**
     * 查询商品库存
     */
    @GetMapping("/getProductStock")
    public Result getProductStock(@RequestParam("skuId") Long skuId){
        log.info("要查询编号为：{} 的商品库存",skuId);
        Integer stock = wareSkuService.getProductStock(skuId);
        return Result.ok(stock);
    }
    /**
     * 扣减库存
     */
    @GetMapping("/reduceWare/{skuId}/{count}")
    public Result reduceWare(@PathVariable("skuId") Long skuId,
                             @PathVariable("count") Integer count){
        log.info("扣减商品skuId为{}的库存,扣减数量为{}",skuId,count);
        wareSkuService.reduceWare(skuId,count);
        return Result.ok();
    }

}
